﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace WpfApplicationWithGrid
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.Top = 200;
            this.Left = 500;
            InitializeComponent();
            BitmapImage logo = new BitmapImage();
            logo.BeginInit();
            logo.UriSource = new Uri("logo.gif",UriKind.Relative);
            logo.EndInit();
            this.image1.Source = logo;
            this.image1.Width = logo.Width;
            this.image1.Height = logo.Height;

            
            jsonConverter j = jsonConverter.getConverter();

            
       //     MessageBox.Show(j.setParameterToJson());


        }

        private void button_exit_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();        }

        private void image1_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void button_login_Click(object sender, RoutedEventArgs e)
        {
            if (textBox_username.Text == null || textBox_username.Text == "" ||
                passwordBox_password.Password == null || passwordBox_password.Password == "")
            {
                MessageBox.Show("Account Name or Password field can't be blank ! ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }
            else
            {
                string pairs = "username=" + textBox_username.Text + "&password=" + passwordBox_password.Password;


                Communication c = Communication.getCommunication();




                if (c.testConnection())
                {
                    Window newConfiguration = new Configuration(textBox_username.Text);
                    newConfiguration.Top = 50;
                    newConfiguration.Left = 500;
                    newConfiguration.Show();
                    this.Close();

                }
                else
                {
                    MessageBox.Show("Can't connect to the server ! Please try again later !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            //set up communication here to update the parameter
            
            
            
        }

        private void button_reset_Click(object sender, RoutedEventArgs e)
        {
            textBox_username.Text = "";
            passwordBox_password.Password = "";
        }

       
    }
}
